package com.yy.bootdemo.admin.controller;

import com.yy.bootdemo.admin.dto.MenuIndexDto;
import com.yy.bootdemo.admin.service.MenuService;
import com.yy.bootdemo.security.dto.JwtUserDto;
import com.yy.bootdemo.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yy
 * @createTime 2022/8/1
 */
@RestController
@RequestMapping("/api")
@Api(tags = "系统：菜单路由")
public class AdminController {
    @Autowired
    private MenuService menuService;

    @GetMapping(value = "/index")
    @ApiOperation(value = "通过用户id获取菜单")
    public R getMenu() {
        JwtUserDto jwtUserDto = (JwtUserDto)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Integer userId = jwtUserDto.getMyUser().getUserId();
        return R.ok(menuService.getMenu(userId));
    }
    @GetMapping(value = "/list")
    
    @ApiOperation(value = "通过用户id获取菜单")
    public List<MenuIndexDto> list() {
        JwtUserDto jwtUserDto = (JwtUserDto)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Integer userId = jwtUserDto.getMyUser().getUserId();
        return menuService.getMenu(userId);
    }
    


}
